package com.example.user.controller;


import annotation.RequireRoles;
import com.example.user.service.ProductimageServiceImpl;
import entity.PageParam;
import entity.Rsp;
import entity.Productimage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 模块接口
 */

@RestController
@Api(value = " 模块接口",description=" 模块接口")
public class ProductimageController {

    private static final Logger log = LoggerFactory.getLogger(ProductimageController.class);

    @Autowired
    ProductimageServiceImpl productimageService;



    @PostMapping("/searchSomeProductimageByPage")
    @RequireRoles(roles = {"admin","super_admin"},index = 2)
    @ApiOperation("查询所有 支持 多条件 分页 排序 查询")
    public Rsp searchSomeByPage(@RequestBody PageParam<Productimage> productimagePageParam,
                                @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){

        log.info("userId:{}",userId);
        log.info("roleId:{}",roleSign);

        return Rsp.success(productimageService.searchSomeByPage(productimagePageParam));
    }


    @RequireRoles(roles = {"super_admin","admin"},index = 2)
    @PostMapping("/addOneProductimage")
    @ApiOperation("添加单个")
    public Rsp addOne(@RequestBody @Valid Productimage productimage, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){

        productimage.setCreateUserId(userId);
        return productimageService.addOne(productimage);
    }


    @RequireRoles(roles = {"super_admin"},index = 2)
    @PostMapping("/deleteOneProductimageTrue")
    @ApiOperation("通过ID物理删除")
    public Rsp deleteOneProductimageTrue(@RequestBody Productimage productimage, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){

        return productimageService.deleteOneTrue(productimage.getId());
    }

    @RequireRoles(roles = {"super_admin","admin"},index = 2)
    @PostMapping("/updateProductimage")
    @ApiOperation("动态修改")
    public Rsp updateProductimage(@RequestBody Productimage productimage, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){


        productimage.setUpdateUserId(userId);
        return productimageService.update(productimage);
    }

    @RequireRoles(roles = {"super_admin"},index = 2)
    @PostMapping("/deleteProductimageLogical")
    @ApiOperation("通过ID逻辑删除")
    public Rsp deleteProductimageLogical(@RequestBody Productimage productimage, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){



        return productimageService.deleteLogical(productimage);
    }

    @RequireRoles(roles = {"super_admin"},index = 2)
    @PostMapping("/recoverProductimageLogical")
    @ApiOperation("逻辑恢复")
    public Rsp recoverProductimageLogical(@RequestBody Productimage productimage, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){



        return productimageService.recoverLogical(productimage);
    }


    @RequireRoles(roles = {"super_admin"},index = 2)
    @PostMapping("/deleteBatchProductimageTrue")
    @ApiOperation("批量物理删除")
    public Rsp deleteBatchProductimageTrue(@RequestBody List<String> ids, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){



        return productimageService.deleteBatchTrue(ids);
    }

    @RequireRoles(roles = {"super_admin"},index = 2)
    @PostMapping("/deleteBatchProductimageLogical")
    @ApiOperation("批量逻辑删除")
    public Rsp deleteBatchProductimageLogical(@RequestBody List<String> ids, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){



        return productimageService.deleteBatchLogical(ids);
    }

    @RequireRoles(roles = {"super_admin"},index = 2)
    @PostMapping("/deleteSomeProductimageLogicalByCondition")
    @ApiOperation("条件逻辑删除")
    public Rsp deleteSomeProductimageLogicalByCondition(@RequestBody Productimage productimage, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){



        return productimageService.deleteSomeLogicalByCondition(productimage);
    }

    @RequireRoles(roles = {"super_admin"},index = 2)
    @PostMapping("/deleteSomeProductimageTrueByCondition")
    @ApiOperation("条件物理删除")
    public Rsp deleteSomeProductimageTrueByCondition(@RequestBody Productimage productimage, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){



        return productimageService.deleteSomeTrueByCondition(productimage);
    }


}
